<?php
include 'db/database_tool.php';
session_start();
class User {
	// property declaration
	public $username = "";
	public $password = "";
	
	// method declaration
	public function displayVar() {
		echo $this->var;
	}
}
//action
function addRoom() {
	// $sql = "insert into room values ($room_num,'','','','','')";
// echo execute($sql);
}
$user = new User ();
//action
function login() {
	if (($_POST ['username'] == "clyde" || $_POST ['username'] == "mengjiao") && $_POST ['password'] == '111') {
		global $user;
		$user->username = $_POST ['username'];
		$user->password = $_POST ['password'];		
		$_SESSION ['user'] = $user;
		echo "success";
	} else {
		echo "failure";
	}

}
//action
function logout() {
	unset($_SESSION['user']);
	echo "success";
}

/**
 * get all properties of each room.
 * @return json
 */
function getAllRoomStates(){
	$sql = "select room_num,left_user_id,right_user_id,status,go_user_record_id from room";
    return query_array($sql);
	
}

if (isset($_POST ['method'])) {
	if ($_POST ['method'] == 'addRoom') {
		addRoom ();
	} else if ($_POST ['method'] == 'login') {
		login ();
	} else if ($_POST ['method'] == 'logout') {
		logout ();
	}
}

?>